﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using jQueryDotNetLib.Extenders;

namespace jQueryDotNetLib.Extras.Extenders
{
    [ToolboxItem(true)]
    [ToolboxData("<{0}:MaskedInput Selector=\"\" runat=server />")]
    public class MaskedInput : BaseInteractionExtender
    {
        public MaskedInput()
        {
            Interaction = "mask";
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Mask
        {
            get
            {
                if (ViewState["Mask"] == null) return "";
                return (string)ViewState["Mask"];
            }
            set
            {
                ViewState["Mask"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Placeholder
        {
            get
            {
                if (ViewState["Placeholder"] == null) return "";
                return (string)ViewState["Placeholder"];
            }
            set
            {
                ViewState["Placeholder"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string OnClientCompleted
        {
            get
            {
                if (ViewState["OnClientCompleted"] == null) return "";
                return (string)ViewState["OnClientCompleted"];
            }
            set
            {
                ViewState["OnClientCompleted"] = value;
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            ConstructorParameters = "\"" + Mask + "\"";
            if(Placeholder!="") base.AddParameter("placeholder", "\"" + Placeholder + "\"");
            if(OnClientCompleted!="") base.AddBinding("completed", OnClientCompleted);

            base.Render(writer);
        }
    }
}
